package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    
    @Select("SELECT * FROM user WHERE id = #{id}")
    UserDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM user WHERE username = #{username}")
    UserDO findByUsername(@Param("username") String username);
    
    @Select("SELECT * FROM user")
    List<UserDO> findAll();
    
    @Insert("INSERT INTO user(username, password, create_time, update_time) " +
            "VALUES(#{username}, #{password}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserDO userDO);
    
    @Update("UPDATE user SET username = #{username}, password = #{password}, " +
            "update_time = NOW() WHERE id = #{id}")
    int update(UserDO userDO);
    
    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
} 